// 引入路由
const fs = require('fs');

const routes = (router, app) => {
  const files = fs.readdirSync(__dirname);
  files.forEach(filename => {
    if (filename.endsWith('.js') && filename !== 'index.js') {
      const fn = require(`./${filename}`);
      const name = filename.split('.')[0];
      fn(router, `/api/${name}`, app);
    }
  })
  app.use(router)
}

module.exports = routes;